<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="referrer" content="never">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>搜索呀</title>
		<link rel="stylesheet" href="/layui/css/layui.css" media="all">
		<style>
			.flow-default {
				width: auto;
				height: auto;
				overflow: auto;
				font-size: 0;
			}
			
			.flow-default li {
				display: inline-block;
				margin: 0 5px;
				font-size: 14px;
				width: 44%;
				margin-bottom: 10px;
				height: 44%;
				line-height: 200%;
				text-align: center;
				background-color: #eee;
			}
			
			.flow-default img {
				width: 100%;
				height: 100%;
			}
		</style>
	</head>
	<script src="/layui/layui.js" charset="utf-8"></script>

	<body>
		<div class="layui-tab-content">
			<form class="layui-form" action="" id="form" name="form">
				<div class="layui-form-item">
					<div class="layui-col-xs9">
						<input type="text" id="word" name="word" placeholder="请输入标题" class="layui-input" style="width: 90%;">
					</div>
					<div class="layui-col-xs3">
						<button type="button" class="layui-btn layui-btn-normal" onclick="getData()">查询</button>
					</div>
				</div>

				<div class="layui-inline" onclick="getData()">
					<input type="radio" name="type" value="tencent" title="腾讯视频" checked lay-filter="type">
					<input type="radio" name="type" value="iqiyi" title="爱奇艺" lay-filter="type">
					<input type="radio" name="type" value="youku" title="优酷" lay-filter="type">
					<input type="radio" name="type" value="mg" title="芒果TV" lay-filter="type">
					<input type="radio" name="type" value="rr" title="人人视频" lay-filter="type">
				</div>
			</form>
		</div>
		<ul id="list" class="flow-default" style="text-align: center;"></ul>
	</body>

	<script>
		layui.use('form', function() {
			var $ = layui.jquery;
			var form = layui.form;
			$("#word").val(getRequest().word);
			$("input[value=" + getRequest().type + "]").click();
			form.render();
			getData();

			$('#word').on('input propertychange', function() {
				getData();
			}); 
		}); 

		function getData() {
			layui.use('flow', function() {
				var $ = layui.jquery;
				var flow = layui.flow;
				var word = $("#word").val();
				if(word == null || word == "") return;
				var type = $("input[name='type']:checked").val();
				$("#list").html(" ");
				flow.load({
					elem: '#list',
					isAuto: true,
					isLazyimg: true,
					done: function(page, next) {
						var lis = [];
						$.get("/" + type + "/getSearchRes?word=" + word, function(res) {
							res = JSON.parse(res)
							layui.each(res, function(index, item) {
								var cli = '';
								if(type == "rr") {
									cli = 'onclick="window.open(&apos;/rrInfo.html/?aid=' + item.url + '&apos;)"';
								} else if(item.type == "mv") {
									cli = 'onclick="window.open(&apos;https://vip.bljiex.com/?v=' + item.url + '&apos;)"';
								} else if(type == "tencent") {
									cli = 'onclick="window.open(&apos;/tvInfo.html/?type=tencent&url=' + item.url + '&apos;)"';
								} else if(type == "iqiyi") {
									cli = 'onclick="window.open(&apos;/tvInfo.html/?type=iqiyi&aid=' + item.aid + '&size=3350&apos;)"';
								} else if(type == "youku") {
									cli = 'onclick="window.open(&apos;/tvInfo.html/?type=youku&url=' + item.url + '&apos;)"';
								}else if(type == "mg") {
									cli = 'onclick="window.open(&apos;/tvInfo.html/?type=mg&clipId='+item.clipId+'&partId='+item.partId  + '&apos;)"';
								}
								lis.push('<li ' + cli + '><img title="' + item.title + '" lay-src="' + item.pic + '"><span >' + item.title + '</span></li>');
							});
							next(lis.join(''), false);
						});
					}
				});
			});
		}
		//获取url中"?"符后的字串
		function getRequest() {
			var url = location.search;
			var theRequest = new Object();
			if(url.indexOf("?") != -1) {
				var str = url.substr(1);
				strs = str.split("&");
				for(var i = 0; i < strs.length; i++) {
					theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
				}
			}
			return theRequest;
		}
	</script>

</html>